﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllProductDataAction:BestLifeDataAction<List<Product>>
    {
        public BestLifeGetAllProductDataAction()
        {
            
        }

        public override List<Product> Body(SqlConnection PConn)
        {
            try
            {
                List<Product> LvList = new List<Product>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetAllProduct";

                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Product LvItem = new Product();
                    LvItem.BarCode = LvReader.GetValue(0).ToString();
                    LvItem.Brand_Name = LvReader.GetValue(0).ToString();
                    LvItem.Cat_ID = LvReader.GetValue(0).ToString();
                   // LvItem.Date_Create = LvReader.GetValue(0).ToString();
                    LvItem.Description = LvReader.GetValue(0).ToString();
                  //  LvItem.Last_Modify = LvReader.GetValue(0).ToString();
                    LvItem.PL_ID = LvReader.GetValue(0).ToString();
                    LvItem.Pro_ID = LvReader.GetValue(0).ToString();
                    LvItem.Pro_Name = LvReader.GetValue(0).ToString();
                    LvItem.Status = LvReader.GetValue(0).ToString();
                    LvItem.Subcat_ID = LvReader.GetValue(0).ToString();
                  //  LvItem.Unit = LvReader.GetValue(0).ToString();
                   // LvItem.Unit_DescriptionLvReader.GetValue(0).ToString();
                    LvItem.User_Id = LvReader.GetValue(0).ToString();
                    LvItem.User_Modify = LvReader.GetValue(0).ToString();

                    LvList.Add(LvItem);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
